package com.silence.thread.safe;

import java.util.Locale;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Account {
    private String card;
    private double money;

    private final Lock lock = new ReentrantLock();

    public Account() {
    }

    public Account(String card, double money) {
        this.card = card;
        this.money = money;
    }

    public String getCard() {
        return card;
    }

    public void setCard(String card) {
        this.card = card;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public void drawMoney(Double money) {
        lock.lock();
        Thread thread = Thread.currentThread();
        if (this.money < money){
            System.out.println(thread.getName()+"来取钱，余额不足");
        }else{
            System.out.println(thread.getName()+"来取钱，成功");
            this.money -= money;
            System.out.println(thread.getName()+"来取钱,余额"+this.money);
        }
        lock.unlock();
    }
}
